package com.zdd.ehe.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdd.ehe.entity.DiseaseData;
import com.zdd.ehe.entity.Role;
import com.zdd.ehe.entity.User;
import com.zdd.ehe.mapper.DiseaseDataMapper;
import com.zdd.ehe.service.IDiseaseDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhuiZhu
 * @since 2023-03-24
 */
@Service
public class DiseaseDataServiceImpl extends ServiceImpl<DiseaseDataMapper, DiseaseData> implements IDiseaseDataService {
    @Resource
    private DiseaseDataMapper diseaseDataMapper;

    /**
     * 分页查询病虫害列表
     *
     * @param page
     * @return
     */
    @Override
    public Page<DiseaseData> getAllDiseaseByPage(Page<DiseaseData> page) {
        Page<DiseaseData> pagex = diseaseDataMapper.getAllDiseaseByPage(page);
        return pagex;
    }

    @Override
    public List<String> getDiseaseData(String name) {
        List<String> diseaseDataList = diseaseDataMapper.getDiseaseData(name);
        return diseaseDataList;
    }

    @Override
    public int update(DiseaseData diseaseData) {
        int result = -1;
        try{
            result = diseaseDataMapper.updateById(diseaseData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 添加病虫害信息
     * @param diseaseData
     * @return
     */
    @Override
    public int addDiseaseData(DiseaseData diseaseData) {
        int result = -1;
        try {
            result = diseaseDataMapper.insert(diseaseData);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }


}
